'''
Created on 2020年3月2日

@author: Administrator
'''
from peewee import *
from config import *

db = MySQLDatabase(DB_NAME,host =DB_HOST,user=DB_USER,passwd=DB_PASSWORD);
#连接数据库
db.connect();
# db = SqliteDatabase(DB_PATH)

class BaseModel(Model):
    class Meta:
        database = db

#职位        
class Position(BaseModel):
    # id = IntegerField(null=False)
    name = CharField(null=False)

    class Meta:
        db_table = 'position'

# 面试补充表
class RegistSupplement(BaseModel):
    # 外键
    r_id = IntegerField(null = False)
    # 来源
    source = CharField(null = False)
    # 介绍人
    invitees = CharField(null = False)
    # 初试人
    first_tester = CharField(null = False)
    # 复试人
    retester = CharField(null = False)
    # 初试人评价
    ft_comment = CharField(null = False)
    # 复试人评价
    rt_comment = CharField(null = False)
    # 邀约日期
    invitee_date = DateTimeField()
    update_time = DateTimeField()
    add_time = DateTimeField()

    class Meta:
        db_table = 'regist_supplement'
# 考试表
class Test(BaseModel):
    id = IntegerField(null = False)
    # 考试名称
    name = CharField(null = False)
    # 大分类
    type = CharField(null = False)
    # 小分类
    stype = CharField(null = False)
    # 总题目数
    total_number = IntegerField(null = False)
    # 总分
    total_score = CharField(null = False)
    end_time = DateTimeField()
    add_time = DateTimeField()
    update_time = DateTimeField()
    examine_number = IntegerField(null = False)
    # 第几次考试
    pass_number = IntegerField(null = False)
    # 通过分数
    pass_mark = CharField(null = False)
    # 考试次数
    test_total_times = IntegerField(null = False)
    state = CharField(null = False)

    class Meta:
        db_table = 'examination'
# 试卷表
class TestPaper(BaseModel):
    id = IntegerField(null = False)
    # 得分
    score = CharField(null = False)
    # 考了几次
    test_number = IntegerField(null = False)
    # 人名
    name = CharField(null = False)
    # 身份证
    identity_card = CharField(null = False)
    # 通过分数
    pass_mark = CharField(null = False)
    # 考试类型
    test_type = CharField(null = False)
    # 总分
    total_score = CharField(null = False)
    add_time = DateTimeField()
    update_time = DateTimeField()
    # 问题数量
    question_total = CharField(null = False)
    # 系列id
    series_id = IntegerField(null = False)
    # 考试表外键
    exam_id = IntegerField(null = False)
    class Meta:
        db_table = 'test'


# 题库表
class QuestionBank(BaseModel):
    # 大分类
    type = CharField(null = False)
    # 小分类
    stype = CharField(null = False)
    # 单选多选
    question_type = CharField(null = False)
    # 正确答案
    rightchoose = CharField(null = False)
    # 题目
    ti_mu = CharField(null = False)
    # 选择
    xuan_xiang = CharField(null = False)
    add_time = DateTimeField()
    update_time = DateTimeField()

    class Meta:
        db_table = 'question_bank'


# 试卷明细表
class TestDetails(BaseModel):
    test = ForeignKeyField(TestPaper)
    test_id = IntegerField(null = False)
    question_bank = ForeignKeyField(QuestionBank)
    # 回答答案
    answer_results = CharField(null = False)
    # 是否正确
    is_right = CharField(null = False)

    class Meta:
        db_table = 'test_details'


#应聘表
class RegistrationSheet(BaseModel):
    # 名字
    name = CharField(null = False)
    # 性别
    sex = CharField(null = False)
    # 生日
    birthday = CharField(null = False)
    # 应聘岗位
    position = CharField(null = False)
    # 地点 无锡徐州绍兴
    local = CharField(null = False)
    # 婚姻情况
    marital_status = CharField(null = False)
    # 身份证
    identity_card = CharField(null = False)
    # 电话
    tel = IntegerField(null = False)
    # 祖籍
    registered_permanent_residence = CharField(null = False)
    # 现居住地址
    residential_address = CharField(null = False)
    # 紧急联络人
    urgent_name = CharField(null = False)
    # 紧急联络人电话
    urgent_tel = IntegerField(null = False)
    # 期望薪资
    salary_expectation = CharField(null = False)
    # 最快到岗日期
    fastest_work_time = CharField(null = False)
    # 学历开始日期
    learn_start_time = CharField(null = False)
    # 学历结束日期
    learn_end_time = CharField(null = False)
    # 学校名称
    school_name = CharField(null = False)
    # 统考自考
    examination_type = CharField(null = False)
    # 专业
    major = CharField(null = False)
    # 学历
    educationlist = CharField(null = False)
    # 是否毕业
    graduate_type = CharField(null = False)
    add_time = DateTimeField()
    # 汉族
    nation = CharField(null = False)
    # 身高
    stature = CharField(null = False)
    # 体重
    weight = CharField(null = False)
    # 邮箱
    e_mail = CharField(null = False)
    # 身体情况
    health = CharField(null = False)
    # 会计证
    certificate_level = CharField(null = False)
    # 英语等级
    english_level = CharField(null = False)
    # 自我评价
    self_comment = CharField(null = False)
    # 特长
    specialty = CharField(null = False)
    # 工作经历
    workexperience = CharField(null = False)
    # 家庭情况
    family = CharField(null = False)
    update_time = DateTimeField()
    # 是否完善
    perfect_flag = CharField(null = False)
    # 签名
    imgbase64 = TextField()
    # 备注
    remake = CharField(null = False)
    # 是否通过
    pass_type = CharField(null = False)
    # 开户银行
    open_bank = CharField(null = False)
    # 银行卡号
    account_number = CharField(null = False)
    # 是否提醒
    remind = CharField(null = False)
    # 提醒内容
    remind_content = CharField(null = False)
    # 提醒时间
    remind_time = DateTimeField()
    class Meta:
        db_table = 'registrationsheet'
#部门
class Dept(BaseModel):
    # 部门名称
    name = CharField(null=False)
    # 上级部门ID
    up_id = IntegerField(null=False)
    # 分类
    type = CharField(null=False)
    class Meta:
        db_table = 'dept'
#区域
class Area(BaseModel):
    # 区域名称
    areaname = CharField(null=False)

    class Meta:
        db_table = 'area'

class User(BaseModel):
    username = CharField(null=False)
    password = CharField(null=False)
    isactive = CharField(null=False)
    sex = CharField(null=False)
    birthday = DateField()
    address = CharField(null=False)
    phone = CharField(null=False)
    idcards = TextField(null=False)
    dept = ForeignKeyField(Dept)
    # #职位
    position = ForeignKeyField(Position)
    #在职状态
    workstatus = CharField(null=False)
    #工作地点
    workplace = CharField(null=False)
    # 团队主管ID
    leader_id = IntegerField(null=False)
    # 是否部门经理
    ismanager = CharField(null=False)
    # 是否团队主管
    isleader = CharField(null=False)
    # 入职日期
    employdate =DateField()
    # 离职日期
    leavedate =DateField()
    # 状态
    status =CharField()

    position_id = IntegerField(null=False)
    class Meta:
        db_table = 'user'

class AppGroup(BaseModel):
    groupname = CharField(null=False)
    class Meta:
        db_table = 'appgroup'

class AllApp(BaseModel):
    id = IntegerField(null=False)
    path = CharField(null=False)
    imgsrc = TextField(null=False)
    text = CharField(null=False)
    group_id = ForeignKeyField(AppGroup)
    class Meta:
        db_table = 'allapp'

class UserApp(BaseModel):
    user_id = ForeignKeyField(User,on_delete='CASCADE')
    app_id = ForeignKeyField(AllApp,on_delete='CASCADE')
    class Meta:
        db_table = 'userapp'

class PositionApp(BaseModel):
    id = IntegerField(null=False)
    position_id = ForeignKeyField(Position,on_delete='CASCADE')
    app_id = ForeignKeyField(AllApp,on_delete='CASCADE')
    class Meta:
        db_table = 'positionapp'

#工商注册主表
class GongShang(BaseModel):
    # 公司名称，多个用逗号分隔
    companyname = CharField(null=False)
    # 经营范围
    businessscope = CharField(null=False)
    # 纳税类型 一般纳税人、小规模
    taxtype = CharField(null=False)
    # 注册资金
    registeredcapital= IntegerField(null=False)
    # 缴纳类型 认缴、实缴
    paytype = CharField(null=False)
    #企业类型 有限公司、无限公司、股份公司
    comtype = CharField(null=False)
    # 注册地址说明(客户提供或公司提供)
    registeredaddress= CharField(null=False)
    # 上传产权证明
    securities= TextField(null=False)
    # 上传租赁协议
    leasingagreements= TextField(null=False)
    # 是否房屋发票
    ishouseinvoice= CharField(null=False)
    # 刻章说明
    chaptermoment= CharField(null=False)
    # 联系人
    liaisons= CharField(null=False)
    # 电话
    phonenumber= CharField(null=False)
    #加急
    urgent= CharField(null=False)
    #状态(客户填写中，客户填写完成，内部审核中，内部审核完成，工商审核中，注册完成)
    status= CharField(null=False)
    # 创建日期
    createtime= DateField()
    # 负责人
    hander = ForeignKeyField(User)
    class Meta:
        db_table = 'gongshang'
#工商注册明细表
class GongShangDetail(BaseModel):
    gongshang = ForeignKeyField(GongShang)
    # 称谓
    title = CharField(null=False)
    # 成员姓名
    name = CharField(null=False)
    # 证件号
    idnumber = CharField(null=False)
    # 手机号
    phonenumber= CharField(null=False)
    # 出资比例
    capitalratio= IntegerField(null=False)
    # 上传证件
    idcards = TextField(null=False)
    class Meta:
        db_table = 'gongshangdetail'

#公共客户
class Customer(BaseModel):
    compname = CharField(null=False)
    # 法人
    legalperson= CharField()
    # 注册资金
    registeredcapital= IntegerField()
    # 经营范围
    businessscope= CharField()
    # 成立日期
    founddate = DateField()

    #区域
    area = CharField()
    address = CharField()
    #联系人
    contacter = CharField()
    phone = CharField()
    #公司类别
    comptype = CharField()
    # 挂靠情况
    affiliation = CharField()
    # 创建日期
    createdatetime= DateTimeField()
    # 更新日期
    updatetime= DateTimeField()
    # 来源
    src = CharField(null=False)
    # 税务类型
    taxtype = CharField(null=False)
    # 分配类型：手动，自动
    assignetype = CharField(null=False)
    # 状态 已分配/未分配
    status = CharField(null=False)
    # 备注
    memo = CharField(null=False)
    # 所属部门
    dept = ForeignKeyField(Dept)
    class Meta:
        db_table = 'customer'

#我的客户
class MyCustomer(BaseModel):
    customer = ForeignKeyField(Customer)
    #销售分类
    saletype = CharField(null=False)
    weixin = CharField(null=False)
    # 添加日期
    adddatetime= DateTimeField()
    # 截止日期
    enddatetime= DateTimeField()
    # 跟踪者
    tracker = ForeignKeyField(User)
    # 状态
    status = CharField(null=False)
    # 更新日期
    updatetime= DateTimeField()
    # 成交金额
    amount = IntegerField()
    # 实际收款
    actualcollection = IntegerField()
    # 尾款金额
    balance = IntegerField()
    # 尾款条件
    balancecondtion = CharField(null=False)
    # 签约方式
    signtype = CharField(null=False)
    #备注
    memo = CharField(null=False)

    class Meta:
        db_table = 'mycustomer'

#跟踪记录
class TrackRecord(BaseModel):
    mycustomer = ForeignKeyField(MyCustomer)
    createtime= DateTimeField()
    # 跟踪事项
    tracktype= CharField(null=False)
    # 跟踪内容
    content= CharField(null=False)
    class Meta:
        db_table = 'trackrecord'

#通知
class Notify(BaseModel):
    # 通知类别 客户信息变更通知，公共客户返回通知
    type= CharField(null=False)
    # 通知内容
    content= CharField(null=False)
    # 被通知者
    notifier = ForeignKeyField(User)
    # 状态 已处理，未处理
    status = CharField(null=False)
    # 处理说明
    memo = CharField()
    createdatetime= DateTimeField()
    updatetime= DateTimeField()
    # 跟踪者
    tracker = ForeignKeyField(User)
    presser = ForeignKeyField(User)
    class Meta:
        db_table = 'notify'

# 暂时没用到TEAM表
class Team(BaseModel):
    # 成员
    member = ForeignKeyField(User)
    # 所属主管
    leader = ForeignKeyField(User)

    class Meta:
        db_table = 'team'

class SummaryTrack(BaseModel):
    # 统计跟踪数
    tracker = ForeignKeyField(User)
    date = DateField()
    # 跟踪数量
    total = IntegerField()
    # 微信数量
    weixin = IntegerField()
    # 各分类数量
    A = IntegerField()
    B = IntegerField()
    C = IntegerField()

    # 面访数量
    visited = IntegerField()
    # 签约数量
    signed = IntegerField()
    # 签约类别 新签、续签、转介绍 数量
    signnew = IntegerField()
    signcontinue = IntegerField()
    signold = IntegerField()
    # 成交金额
    amount = IntegerField()
    # 实际收款
    actualcollection = IntegerField()
    # 尾款金额
    balance = IntegerField()
    # 流转量
    moveto = IntegerField()

    class Meta:
        db_table = 'summarytrack'

class Service(BaseModel):
    '''服务业务'''
    # 业务名称
    name = CharField()
    # 办理时限
    time = IntegerField()
    # 时限单位
    unit = CharField()
    # 备注
    memo = CharField()

    class Meta:
        db_table = 'service'

class ServiceDetail(BaseModel):
    '''服务业务明细'''
    # 服务业务
    service = ForeignKeyField(Service)
    # 规格
    spec = CharField()
    # 类型
    type = CharField()
    # 单位
    unit = CharField()
    # 成本
    cost = IntegerField()
    # 价格
    price = IntegerField()
    # 服务内容
    items = CharField()
    # 备注
    memo = CharField()
    # 是否可用
    isactive = CharField()
    # 数量上限
    countup = IntegerField()
    # 金额上限
    amountup = IntegerField()
    # 默认数量
    number = IntegerField()

    class Meta:
        db_table = 'servicedetail'

class Supplier(BaseModel):
    '''供应商'''
    # 供应商名称
    name = CharField()
    # 城市
    city = CharField()
    #联系人
    contacter = CharField()
    # 联系电话
    tel = CharField()
    # 结算方式
    poclear = CharField()
    # 付款方式
    paytype= CharField()
    # 是否开票
    isinvoice= CharField()
    # 状态 正常/已废弃
    status= CharField()
    # 创建日期
    createdate = DateField()
    # 备注
    remark = CharField()

class SupplierDetail(BaseModel):
    '''供应商明细'''
    # 办理业务
    service = ForeignKeyField(Service)
    # 供应商
    supplier = ForeignKeyField(Supplier)
    # 规格说明
    specs = CharField()
    # 成本
    cost = IntegerField()
    # 价格
    price = IntegerField()
    #区域
    area = CharField()
    # 备注
    memo = CharField()
    # 准入行业
    industry = CharField()
    class Meta:
        db_table = 'supplierdetail'

class Lottery(BaseModel):
    '''抽奖名单'''
    # 抽奖人姓名
    name = CharField()
    # 抽奖人手机号码
    tel = CharField()
    # 单位名称
    company = CharField()
    # 获得抽奖次数
    number = IntegerField()
    # 创建日期
    createdate = DateField()
    # 抽奖日期
    lotterydate = DateField()
    # 已抽奖次数
    lotterynumber = IntegerField()
    # 抽奖结果
    lotteryresult = CharField()
    # 备注
    memo = CharField()
    # 状态 未抽奖/已抽奖
    status = CharField()
    class Meta:
        db_table = 'lottery'

# 档案表
class Document(BaseModel):
    # 档案号
    document_number = CharField(null=False)
    # 客户
    customer = ForeignKeyField(Customer)
    customer_id = IntegerField(null=False)
    # 财税分组
    tax_group = IntegerField(null=False)

    class Meta:
        db_table = 'document'

# 工单表
class WorkOrder(BaseModel):
    # 服务详情
    servicedetail_id = IntegerField(null=False)
    # 领导
    leader = ForeignKeyField(User)
    # 客户
    customer = ForeignKeyField(Customer)
    # 流转单
    transform_id = IntegerField(null=False)
    # 业务名
    name = CharField(null=False)
    # 备注
    remake = CharField(null=False)
    create_time = DateTimeField()
    update_time = DateTimeField()
    enddate = DateField()
    # 合同号
    contract_number = CharField(null=False)
    # 档案号
    document_id = IntegerField(null=False)
    document = ForeignKeyField(Document)

    class Meta:
        db_table = 'workorder'

# 工单详情表
class WorkOrderDetails(BaseModel):
    workorder = ForeignKeyField(WorkOrder)
    # 事项
    matter = CharField(null = False)
    # 状态
    status = CharField(null = False)
    # 负责人
    charger = ForeignKeyField(User)
    # 备注
    remake = CharField(null = False)
    # 证据
    evidence = CharField(null = False)
    create_time = DateTimeField()
    update_time = DateTimeField()
    end_time = DateField()

    class Meta:
        db_table = 'workorder_details'


# 处理事项
class HandleItem(BaseModel):
    service_id = IntegerField(null = False)
    # 事项名
    value = CharField(null = False)

    class Meta:
        db_table = 'handle_item'




# 优惠单
class DiscountList(BaseModel):
    # 关联我的客户表
    customer = ForeignKeyField(Customer)
    # 申请者
    applicant = ForeignKeyField(User)
    # 领导
    leader = ForeignKeyField(User)
    # 领导审批状态
    leaderstatus = CharField(null = False)
    # 经理
    manager = ForeignKeyField(User)
    # 经理审批状态
    managerstatus = CharField(null = False)
    # 状态
    status = CharField(null = False)
    # 原价
    price = CharField(null = False)
    # 优惠后价格
    new_price = CharField(null = False)
    # 优惠描述
    preferential_description = CharField(null = False)
    # 删除标记
    del_flag = CharField(null = False)
    # 截止日期
    end_date = DateTimeField()
    create_time = DateTimeField()
    update_time = DateTimeField()
    # 优惠单类型
    type = CharField(null = False)

    class Meta:
        db_table = 'discount_list'


# 优惠单明细
class DiscountListDetail(BaseModel):
    # 关联优惠单
    discount = ForeignKeyField(DiscountList)
    # 关联服务表
    service = ForeignKeyField(Service)
    #  关联服务明细表
    servicedetail = ForeignKeyField(ServiceDetail)
    # 数量
    amount = CharField(null = False)
    # 备注
    remake = CharField(null = False)
    create_time = DateTimeField()
    update_time = DateTimeField()
    #优惠前金额
    priceb = IntegerField()
    #优惠后金额
    pricea = IntegerField()

    class Meta:
        db_table = 'discountlist_details'


#流转单
class TransForm(BaseModel):
    # 销售员
    seller= ForeignKeyField(User)
    # 出单人
    outformer= ForeignKeyField(User)
    # 来源
    src = CharField()
    # 签约方式
    signtype = CharField()
    # 收款日期
    collectiondate= DateField()
    # 流转日期
    transdate= DateField()
    # 地址类别
    addresstype= CharField()
    #办理业务
    business = CharField()
    # 开票类别
    invoicingtype= CharField()
    # 开票金额
    amountinvoicing = IntegerField()
    # 赠送情况
    gifts = CharField()

    # 总计费用
    amounttotal = IntegerField()
    # 应收
    amountreceivables = IntegerField()
    # 实收
    amountpayin = IntegerField()
    # 尾款
    amountend = IntegerField()
    # 支付方式
    paytype = CharField()
    # 支付截图
    payimg = TextField()
    # 尾款条件
    amountendcondition = CharField()
    # 相关材料
    materials = TextField()
    # 备注
    memo = CharField()
    # 交接人
    handover = ForeignKeyField(User)
    handoverstatus = CharField()
    # 成本审核人
#     coster = ForeignKeyField(User)
    # 成本审核状态
#     costerstatus = CharField()
    # 接收人
    receiver = ForeignKeyField(User)
    # 接收人审核状态
    receiverstatus = CharField()
    # 主管
    supervisor = ForeignKeyField(User)
    # 主管审核状态
    supervisorstatus = CharField()
    # 财务
    finance = ForeignKeyField(User)
    # 财务审核状态
    financestatus = CharField()
    # 状态
    status = CharField()
    annex = CharField()
    # 我的客户ID
    mycustomer = ForeignKeyField(MyCustomer)
    # 公共客户ID
    customer = ForeignKeyField(Customer)
    # 优惠单
    discount = ForeignKeyField(DiscountList)
    # 流转单类型 一般流转/尾款流转
    formtype = CharField()

    class Meta:
        db_table = 'transform'

class TransFormDetail(BaseModel):
    # 流转单ID关联
    transform = ForeignKeyField(TransForm)
    # 服务详情ID关联
    servicedetail = ForeignKeyField(ServiceDetail)
    # 服务关联ID
    service = ForeignKeyField(Service)
    # 数量
    amount = IntegerField()
    # 单位
    unit = CharField()
    # 价格
    price = IntegerField()
    # 收款金额
    totalprice = IntegerField()
    # 成本金额
    cost = IntegerField()
    # 备注
    memo = CharField()
    class Meta:
        db_table = 'transformdetail'

class TransFormRecorder(BaseModel):
    '''流转单收款明细'''
    # 流转单ID关联
    transform = ForeignKeyField(TransForm)
    # 收款日期
    collectiondate= DateField()
    # 收款金额
    totalprice = IntegerField()
    # 收款方式
    loantype = CharField()
    #上传收款截图
    annex = CharField()
    # 备注
    memo = CharField()

    reciver = ForeignKeyField(User)
    class Meta:
        db_table = 'transformrecorder'
        
class Borrow(BaseModel):
    '''借支单'''
    # 所属部门
    dept = ForeignKeyField(Dept)
    # 创建日期
    createdate = DateField()
    # 城市
    city = CharField()
    # 借款金额
    amount = IntegerField()
    # 借款事由
    content = CharField()
    # 状态 待审批/已通过
    status = CharField()
    # 借款方式
    loantype = CharField()
    # 还款方式
    repaytype = CharField()
    # 还款日期
    repaydate = DateField()
    # 借支人
    borrower= ForeignKeyField(User)
    # 主管
    master= ForeignKeyField(User)
    masterstatus= CharField()
    # 审批人
    approver= ForeignKeyField(User)
    approverstatus= CharField()
    # 出纳
    cashier= ForeignKeyField(User)
    cashierstatus= CharField()
    # 会计
    bookkeeper= ForeignKeyField(User)
    bookkeeperstatus= CharField()
    # 付款截图
    annex = CharField()
    # 备注
    memo = CharField()
    class Meta:
        db_table = 'borrow'      

class PayForm(BaseModel):
    '''付款申请单'''
    # 所属部门
    dept = ForeignKeyField(Dept)
    # 创建日期
    createdate = DateField()
    # 付款方式
    paytype = CharField()
    #收款单位
    company = ForeignKeyField(Supplier)
    #收款人
    reciver = CharField()
    #银行账号
    bankno = CharField()
    #开户银行
    bankname = CharField()
    # 汇款金额
    amount = FloatField()
    # 汇款事由
    content = CharField()
    # 状态 待审批/已通过
    status = CharField()
    # 付款日期
    repaydate = DateField()
    # 经办人
    agent= ForeignKeyField(User)
    # 主管
    master = ForeignKeyField(User)
    masterstatus = CharField()
    # 审批人
    approver= ForeignKeyField(User)
    approverstatus= CharField()
    # 出纳
    cashier= ForeignKeyField(User)
    cashierstatus= CharField()
    # 会计
    bookkeeper= ForeignKeyField(User)
    bookkeeperstatus= CharField()
    # 付款截图
    annex = CharField()
    # 备注
    memo = CharField()
    class Meta:
        db_table = 'payform'

class ExpenseForm(BaseModel):
    '''报销单'''
    # 所属部门
    dept = ForeignKeyField(Dept)
    # 创建日期
    createdate = DateField()
    # 报销方式
    expensetype = CharField()
    # 报销金额
    amount = IntegerField()
    # 报销事由
    content = CharField()
    # 状态 待审批/已通过
    status = CharField()
    # 报销人
    agent= ForeignKeyField(User)
    # 主管
    master= ForeignKeyField(User)
    masterstatus= CharField()
    # 审批人
    approver= ForeignKeyField(User)
    approverstatus= CharField()
    # 出纳
    cashier= ForeignKeyField(User)
    cashierstatus= CharField()
    # 会计
    bookkeeper= ForeignKeyField(User)
    bookkeeperstatus= CharField()
    # 付款截图
    annex = CharField()
    # 备注
    memo = CharField()
    class Meta:
        db_table = 'expenseform'


# 内部工单表
class Company(BaseModel):
    # 协助部门审核人
    leader_id = IntegerField(null = False)
    leader = ForeignKeyField(User) 
    # 申请人
    applicant_id = IntegerField(null = False)
    applicant = ForeignKeyField(User) 
    # 本部门审核人
    audit_leader_id = IntegerField(null = False)
    audit_leader = ForeignKeyField(User)
    # 本部门审核状态
    audit_leader_status = CharField(null = False)
    # 协助部门审核状态
    leader_status = CharField(null = False)
    # 状态
    status = CharField(null = False)
    # 标题
    title = CharField(null = False)
    # 备注
    remake = CharField(null = False) 
    # 需办事项证据
    evidence = CharField(null = False)
    create_time = DateTimeField()  
    update_time = DateTimeField()  
    enddate = DateField() 

    class Meta:
        db_table = 'company'


# 内部工单详情表
class CompanyDetails(BaseModel):
    company_id = IntegerField(null = False)
    # 事项
    matter = CharField(null = False)
    # 状态
    status = CharField(null = False) 
    # 负责人
    charger = ForeignKeyField(User) 
    charger_id = IntegerField(null = False)
    # 备注
    remake = CharField(null = False) 
    # 证据
    evidence = CharField(null = False) 
    create_time = DateTimeField()  
    update_time = DateTimeField()  
    end_time = DateField() 
    class Meta:
        db_table = 'company_details'


# 代理记账
class AgentKeeping(BaseModel):
    # 服务详情
    servicedetail_id = IntegerField(null = False)
    # 客户
    customer = ForeignKeyField(Customer) 
    # 领导人
    leader = ForeignKeyField(User) 
    leader_id = IntegerField(null = False)
    # 流转单
    transform_id = IntegerField(null = False)
    # 流转单详情
    transform_detail_id = IntegerField(null = False)
    # 单位
    unit = CharField(null = False)
    # 数量
    amount = IntegerField(null = False) 
    # 服务名
    name = CharField(null = False)
    # 备注
    remake = CharField(null = False) 
    create_time = DateTimeField()  
    update_time = DateTimeField()  
    enddate = CharField(null = False)
    # 合同号
    contract_number = CharField(null = False)
    # 档案
    document_id = IntegerField(null = False)
    document = ForeignKeyField(Document) 
    # 税控盘
    TCP = CharField(null = False) 
    # 续签
    renew = CharField(null = False)
    # 社保公积金
    sbgjj = CharField(null = False)
    # 账本状态
    status = CharField(null = False)

    class Meta:
        db_table = 'trans_agentkeeping'


class AgentKeepingDetails(BaseModel):
    # 记账
    keepaccount = ForeignKeyField(AgentKeeping)
    # 事项
    matter = CharField(null = False)
    # 状态
    status = CharField(null = False) 
    # 负责人
    charger = ForeignKeyField(User)
    # 备注
    remake = CharField(null = False) 
    # 月份
    month = CharField(null = False)
    # 证据
    evidence = CharField(null = False) 
    create_time = DateTimeField()  
    update_time = DateTimeField()  

    class Meta:
        db_table = 'agentkeeping_details'
        
class Matter (BaseModel):
    sort = IntegerField(null = False)
    name = CharField(null = False)
    class Meta:
        db_table = 'matter'
        
# 工单表
class WorkOrder(BaseModel):
    # 服务详情
    servicedetail_id = IntegerField(null = False)
    # 领导
    leader_id = IntegerField(null = False)
    leader = ForeignKeyField(User) 
    # 客户
    customer = ForeignKeyField(Customer) 
    # 流转单
    transform = ForeignKeyField(TransForm)
    # 业务名
    name = CharField(null = False)
    # 备注
    remake = CharField(null = False) 
    create_time = DateTimeField()  
    update_time = DateTimeField()  
    enddate = DateField() 
    # 合同号
    contract_number = CharField(null = False)
    # 档案号
    document_id = IntegerField(null = False)
    document = ForeignKeyField(Document)  

    class Meta:
        db_table = 'workorder'


# 考试分类表
class ExamType(BaseModel):
    # 考试名称
    type_name = CharField(null = False)
    # 上级考试分类（大分类）
    up_type_id = IntegerField(null = False)

    class Meta:
        db_table = 'examtype'


# 考勤主表
class WorkattendanceMaster(BaseModel):
    # 员工姓名
    user = ForeignKeyField(User)
    # 考勤年月
    attendancetime = CharField(null=False)
    # 是否签名
    ifwritename = CharField(null=False)
    # 签名
    writename = TextField()

    class Meta:
        db_table = 'workattendancemaster'


# 考勤明细表
class WorkattendanceDetails(BaseModel):
    # 日期
    date = DateField()
    # 星期
    week = CharField(null=False)
    # 工作日
    day = CharField(null=False)
    # 状态
    status = CharField(null=False)
    # 出勤时间
    attendancetime = DateTimeField()
    # 退勤时间
    noattendancetime = DateTimeField()
    # 连接主表
    workattendancemaster = ForeignKeyField(WorkattendanceMaster)

    class Meta:
        db_table = 'workattendancedetails'

    # 申请主表


class WorkApply(BaseModel):
    # 员工姓名
    user = ForeignKeyField(User)
    # 日期
    date = DateField()
    # 申请类型
    cause = CharField(null=False)
    # 申请状态
    applystatus = CharField(null=False)
    # 申请事由
    reason = CharField(null=False)
    # 审批人
    approvaluser = ForeignKeyField(User)
    # 审批结果
    result = CharField(null=False)
    # 审批日期
    approvaldate = DateField()

    class Meta:
        db_table = 'workapply'

    # 薪资明细主表


class SalaryMaster(BaseModel):
    # 员工姓名
    user = ForeignKeyField(User)
    # 年月
    salarytime = CharField(null=False)
    # 是否签名
    ifwritename = CharField(null=False)
    # 签名
    writename = TextField()

    class Meta:
        db_table = 'salarymaster'

    # 薪资明细


class SalaryDetails(BaseModel):
    # 项目名称
    itemname = CharField(null=False)
    # 金额
    amount = IntegerField(null=False)
    # 连接主表
    salarymaster = ForeignKeyField(SalaryMaster)

    class Meta:
        db_table = 'salarydetails'

#公司发票
class InvoiceCompany(BaseModel):
    id = IntegerField(null=False)

    # 公司customer表id
    customer_id = IntegerField(Customer)

    customer = ForeignKeyField(Customer)
    # document = ForeignKeyField(Document)
    # agentKeeping = ForeignKeyField(AgentKeeping)

    # 发票章
    invoice_seal = CharField(null=False)
    # 备注
    remarks = CharField(null=False)
    # 税号
    duty_paragraph = CharField(null=False)
    # 专票数量
    spaecialticket_number = IntegerField(null=False)
    # 专票限额
    spaecialticket_quota = IntegerField(null=False)
    # 电子专票数量
    electronicspaecialticket_number = IntegerField(null=False)
    # 电子专票限额
    electronicspaecialticket_quota = IntegerField(null=False)
    # 普票数量
    generalticket_number = IntegerField(null=False)
    # 普票限额
    generalticket_quota = IntegerField(null=False)
    # 电子普票数量
    electronicgeneralticket_number = IntegerField(null=False)
    # 电子普票限额
    electronicgeneralticket_quota = IntegerField(null=False)
    # 状态
    status = CharField(null=False)

    class Meta:
        db_table = 'invoice_company'

#发票记录
class InvoiceRecord(BaseModel):
    id = IntegerField(null=False)

    # 公司id
    invoicecompany_id = IntegerField(InvoiceCompany)
    # 发票类型
    billing_type = CharField(null=False)
    # 时间
    billing_time = DateTimeField(null=False)
    # 发票数量
    billing_number = IntegerField(null=False)
    # 状态
    invoice_status = CharField(null=False)
    # 操作人
    billing_person = CharField(null=False)
    # 操作类型
    operation_type = CharField(null=False)

    class Meta:
        db_table = 'invoice_record'
